package com.his.controller;

import com.his.common.Const;
import com.his.common.Rsp;
import com.his.entity.Department;
import com.his.service.DepartmentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Department)表控制层
 *
 * @author makejava
 * @since 2020-10-23 18:07:23
 */
@RestController
@RequestMapping("department")
public class DepartmentController {
    /**
     * 服务对象
     */
    @Resource
    private DepartmentService departmentService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Department selectOne(Integer id) {
        return this.departmentService.queryById(id);
    }


    @PostMapping("getAllFather")
    public Rsp getAllFather() {
        Department department = new Department();
        department.setDepFatherId(0);
        return departmentService.queryAll(department);
    }

    @GetMapping("getCurrentUserDep")
    public Rsp getCurrentUserDep(@RequestHeader(Const.TOKEN) String cookie)  throws Exception{
        return Rsp.success(departmentService.getCurrentUserDep(cookie));
    }

}
